import * as types from './../constants/ActionTypes';

/*
 * 指定日期盘前股讯
 ================================================================*/
export function fetchRecommend(searchdate = ""){
  return  (dispatch) => {
    let payload = {
        recommend_status: 0,
        message: '加载中'
    };
    dispatch({
      payload,
      type: [types.FETCH_RECOMMEND, types.FETCH_RECOMMEND_SUCCESS, types.FETCH_RECOMMEND_FAILURE],
      meta: {
        fetch: [`gaoshou/pq3g?searchdate=${searchdate}`, {
          method: 'get'
        }]
      }  
    });
  };
}

/*
 * 指定日期上交易日盘前股讯
 ================================================================*/
export function fetchLastRecommend(searchdate = ""){
  
  return  (dispatch) => {
    let payload = {
        recommend_last_status: 0,
        message: '加载中'
    };
    dispatch({
      type: [types.FETCH_LAST_RECOMMEND, types.FETCH_LAST_RECOMMEND_SUCCESS, types.FETCH_LAST_RECOMMEND_FAILURE],
      meta: {
        fetch: [`gaoshou/pq3glast?searchdate=${searchdate}`, {
          method: 'get'
        }]
      }  
    });
  };
}

/*
 * 盘前股讯订阅
 ================================================================*/
export function signRecommend() {
  return  (dispatch) => {
    let payload = {
        recommend_sign_status: 0,
        message: '加载中'
    };
    dispatch({
      payload, 
      type: [types.SIGN_RECOMMEND, types.SIGN_RECOMMEND_SUCCESS, types.SIGN_RECOMMEND_FAILURE],
      meta: {
        fetch: [`member/dypq3g?status=1`, {
            method: 'get'
          }
        ]
      }  
    });
  };
}

/*
 * 盘前股讯取消订阅
 ================================================================*/
export function unsignRecommend() {
  return  (dispatch) => {
    let payload = {
        recommend_unsign_status: 0,
        message: '加载中'
    };
    dispatch({
      payload,
      type: [types.UNSIGN_RECOMMEND, types.UNSIGN_RECOMMEND_SUCCESS, types.UNSIGN_RECOMMEND_FAILURE],
      meta: {
        fetch: [`member/dypq3g?status=2`, {
            method: 'get'
          }
        ]
      }  
    });
  };
}
